<?php

require("include/top.php");
header('Content-Type: text/xml; charset=UTF-8');

$data = array();
$infos = array();
$limit = 20;

if(isset($_GET['topic']) && !isset($_GET['cat'])) {
    $topic = Category::get($_GET['topic']);
    $products = $topic->getLastProducts($limit);
    $infos['url'] = $topic->getUrl();
    $infos['title'] = "Les derniers produits ".$topic." sur e-Citizen";
    foreach($products as $p) {
        $n = array();
        $n['nom'] = utf8_encode($p['nom']);
        $n['link'] = $p['url'];
        $n['img'] = $p['imgListing'];
        $n['description'] = utf8_encode(strip_tags($p['descriptif']));
        $date = $p['updated'];
        list($jour,$heure) = explode(' ',$date);
        list($y,$m,$d) = explode('-',$jour);
        list($h,$i,$s) = explode(':',$heure);
        $n['date'] = date("D, d M Y H:i:s +0100", mktime($h,$i,$s,$m,$d,$y));

        $data[] = $n;
    }
}
elseif(isset($_GET['topic']) && isset($_GET['cat'])) {
    $topic = Category::get($_GET['topic']);
    $sub = Subcategory::get($topic['id'], $_GET['cat']);
    $products = $sub->getLastProducts($limit);
    $infos['url'] = $sub->getUrl();
    $infos['title'] = "Les derniers produits ".utf8_encode($topic) . " / " . utf8_encode($sub) . " sur e-Citizen";
    foreach($products as $p) {
        $n = array();
        $n['nom'] = utf8_encode($p['nom']);
        $n['link'] = $p['url'];
        $n['img'] = $p['imgListing'];
        $n['description'] = utf8_encode(strip_tags($p['descriptif']));
        $date = $p['updated'];
        list($jour,$heure) = explode(' ',$date);
        list($y,$m,$d) = explode('-',$jour);
        list($h,$i,$s) = explode(':',$heure);
        $n['date'] = date("D, d M Y H:i:s +0100", mktime($h,$i,$s,$m,$d,$y));

        $data[] = $n;
    }
}
elseif(isset($_GET['vendor'])) {
    $vendor = Vendor::get($_GET['vendor']);
    $infos['title'] = "Les derniers produits de ".utf8_encode($vendor)." sur e-Citizen";
    $infos['url'] = $vendor['url'];
    foreach($vendor->getLastProducts() as $p) {
        $n = array();
        $n['nom'] = utf8_encode($p['nom']);
        $n['link'] = $p['url'];
        $n['img'] = $p['imgListing'];
        $n['description'] = utf8_encode(strip_tags($p['descriptif']));
        $date = $p['updated'];
        list($jour,$heure) = explode(' ',$date);
        list($y,$m,$d) = explode('-',$jour);
        list($h,$i,$s) = explode(':',$heure);
        $n['date'] = date("D, d M Y H:i:s +0100", mktime($h,$i,$s,$m,$d,$y));

        $data[] = $n;
    }
}
elseif(isset($_GET['news'])) {
    
    if($_GET['news'] != "0") {
        $cat = new PostTheme($_GET['news']);
        $infos['title'] = "Les derniers articles de ".utf8_encode($cat)." sur e-Citizen";
        $infos['url'] = $cat['url'];
        $posts = $cat->getPosts($limit);
    } else {
        $infos['title'] = "Les derniers articles sur e-Citizen";
        $infos['url'] = URL_PATH . "articles/";
        $posts = Post::getPosts("added", 0, $limit);
    }

    foreach($posts as $p) {
        $n = array();
        $n['nom'] = utf8_encode($p['titre']);
        $n['link'] = $p['url'];
        $n['img'] = $p['thumb'];
        $n['description'] = utf8_encode(strip_tags($p['contenu']));

        $date = $p['added'];
        @list($jour,$heure) = explode(' ',$date);
        @list($y,$m,$d) = explode('-',$jour);
        @list($h,$i,$s) = explode(':',$heure);
        $n['date'] = date("D, d M Y H:i:s +0100", @mktime($h,$i,$s,$m,$d,$y));

        $data[] = $n;
    }
}

$tpl->assign('data', $data);
$tpl->assign('infos', $infos);
$tpl->display('rss.tpl');

require("include/bottom.php");

?>
